package com.kangtu.demolistener01.listener;

import org.springframework.stereotype.Component;

import javax.servlet.annotation.WebListener;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;

/**
 * @program: demo-weix-pay
 * @description: MyListener
 * @author: 亮子说编程
 * @create: 2021-03-08 18:41
 **/

@Component
public class MyListener implements HttpSessionListener {
    public static int online = 0;

    @Override
    public void sessionCreated(HttpSessionEvent se) {
        System.out.println("创建session,在线用户数:" + (++online));
    }

    @Override
    public void sessionDestroyed(HttpSessionEvent se) {
        System.out.println("销毁session,在线用户数:" + (--online));
        online--;
    }
}
